package org.birtserver.backend.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class IOUtils {

	private static final int BUFFER_SIZE = 2000000;
	
	public static byte[] loadContentOfInputStream(InputStream inputStream) throws IOException {
	  
	  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	  saveInputStreamToOutputStream(inputStream, buffer);
	  return buffer.toByteArray();
	  
	}
	
	public static void saveInputStreamToOutputStream(InputStream inputStream,
			OutputStream outputStream) throws IOException {

		int length;
		byte[] buffer = new byte[BUFFER_SIZE];
		while ((length = inputStream.read(buffer, 0, BUFFER_SIZE)) != -1) {
			outputStream.write(buffer, 0, length);
		}
		outputStream.close();
		inputStream.close();

	}

}
